package com.xsp.entity;

/**
 * @author jay
 * @date 2023/12/21
 * @desc 服务器返回数据给客户端的通用返回结构体
 */
public class CommonResult {
    private String code;
    private String message;
    private Object data;

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getData() {
        return data;
    }

    public static CommonResult error() {
        CommonResult commonResult = new CommonResult();
        commonResult.code = ResponseCode.ERROR;
        return commonResult;
    }

    public static CommonResult error(String message) {
        CommonResult error = error();
        error.message = message;
        return error;
    }

    public static CommonResult success() {
        CommonResult commonResult = new CommonResult();
        commonResult.code = ResponseCode.SUCCESS;
        return commonResult;
    }

    public static CommonResult success(String message) {
        CommonResult success = success();
        success.message = message;
        return success;
    }

    public static CommonResult success(Object data, String message) {
        CommonResult success = success(message);
        success.data = data;
        return success;
    }

    /**
     * 自定义返回格式
     */
    public static CommonResult response(String code, Object data, String message) {
        CommonResult result = new CommonResult();
        result.code = code;
        result.data = data;
        result.message = message;
        return result;
    }
}
